package com.shushan.home.bean;

import com.android.net.bean.NetBaseBean;
import com.shushan.base.Constants;
import com.shushan.pages.bean.ExerciseRecordListBean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: RecordBean
 * @Desciption: //记录页数据bean
 * @author: zhangshihao
 * @date: 2018-09-25
 */
public class RecordBean extends NetBaseBean {

    public int today_answer_num;//今日答题次数
    public int today_exercises_num;//今日答题数量
    public int today_right_num;//今日答对题数量
    public int today_play_time;//今日答题获得时间（分钟）

    private List<TodayPlayListBean> playListBeans = new ArrayList<>();
    private List<ExerciseRecordListBean> recordListBeans = new ArrayList<>();

    @Override
    public void initByJson(JSONObject jsonObject) throws JSONException {
        if(jsonObject == null){
            return;
        }

        JSONObject recordObj = jsonObject.optJSONObject("record");
        today_answer_num = recordObj.optInt("today_answer_num",0);
        today_exercises_num = recordObj.optInt("today_exercises_num",0);
        today_right_num = recordObj.optInt("today_right_num",0);
        today_play_time = recordObj.optInt("today_play_time",0);

        JSONArray playArr = recordObj.optJSONArray("today_play_list");
        if(playArr != null && playArr.length() > 0){
            for(int i=0;i<playArr.length();i++){
                TodayPlayListBean playBean = new TodayPlayListBean();
                playBean.initByJson(playArr.optJSONObject(i));
                playListBeans.add(playBean);
            }
        }

        ExerciseRecordListBean tblxBean = new ExerciseRecordListBean();
        tblxBean.type = Constants.TYPE_SYNC_EXERCISE;
        tblxBean.initByJson(jsonObject.optJSONObject(Constants.SYNC_EXERCISE));
        recordListBeans.add(tblxBean);

        ExerciseRecordListBean szlxBean = new ExerciseRecordListBean();
        szlxBean.type = Constants.TYPE_STRANGE_WORDS_EXERCISE;
        szlxBean.initByJson(jsonObject.optJSONObject(Constants.STRANGE_WORDS_EXERCISE));
        recordListBeans.add(szlxBean);

        ExerciseRecordListBean kylxBean = new ExerciseRecordListBean();
        kylxBean.type = Constants.TYPE_SPEAKING_EXERCISE;
        kylxBean.initByJson(jsonObject.optJSONObject(Constants.SPEAKING_EXERCISE));
        recordListBeans.add(kylxBean);

        ExerciseRecordListBean dclxBean = new ExerciseRecordListBean();
        dclxBean.type = Constants.TYPE_ENGLISH_WORDS_EXERCISE;
        dclxBean.initByJson(jsonObject.optJSONObject(Constants.ENGLISH_WORDS_EXERCISE));
        recordListBeans.add(dclxBean);

        ExerciseRecordListBean tllxBean = new ExerciseRecordListBean();
        tllxBean.type = Constants.TYPE_HEARING_EXERCISE;
        tllxBean.initByJson(jsonObject.optJSONObject(Constants.HEARING_EXERCISE));
        recordListBeans.add(tllxBean);

        ExerciseRecordListBean kslxBean = new ExerciseRecordListBean();
        kslxBean.type = Constants.TYPE_ORAL_CALCULATE_EXERCISE;
        kslxBean.initByJson(jsonObject.optJSONObject(Constants.ORAL_CALCULATE_EXERCISE));
        recordListBeans.add(kslxBean);

        ExerciseRecordListBean znlxBean = new ExerciseRecordListBean();
        znlxBean.type = Constants.TYPE_SMART_EXERCISE;
        znlxBean.initByJson(jsonObject.optJSONObject(Constants.SMART_EXERCISE));
        recordListBeans.add(znlxBean);

        ExerciseRecordListBean ywZxlxBean = new ExerciseRecordListBean();
        ywZxlxBean.type = Constants.TYPE_CHINESE_SECT_EXERCISE;
        ywZxlxBean.initByJson(jsonObject.optJSONObject(Constants.CHINESE_BRANCH_EXERCISE));
        recordListBeans.add(ywZxlxBean);

        ExerciseRecordListBean sxZxlxBean = new ExerciseRecordListBean();
        sxZxlxBean.type = Constants.TYPE_MACH_SECT_EXERCISE;
        sxZxlxBean.initByJson(jsonObject.optJSONObject(Constants.MATH_BRANCH__EXERCISE));
        recordListBeans.add(sxZxlxBean);

        ExerciseRecordListBean yyZxlxBean = new ExerciseRecordListBean();
        yyZxlxBean.type = Constants.TYPE_ENGLISH_SECT_EXERCISE;
        yyZxlxBean.initByJson(jsonObject.optJSONObject(Constants.ENGLISH_BRANCH__EXERCISE));
        recordListBeans.add(yyZxlxBean);

    }

    public List<TodayPlayListBean> getPlayListBeans() {
        return playListBeans;
    }

    public List<ExerciseRecordListBean> getRecordListBeans() {
        return recordListBeans;
    }

    public class TodayPlayListBean extends NetBaseBean{
        public String app_name;
        public int duration;//秒
        @Override
        public void initByJson(JSONObject jsonObject) throws JSONException {
            if(jsonObject == null){
                return;
            }
            app_name = jsonObject.optString("app_name");
            duration = jsonObject.optInt("duration");
        }
    }

}
